﻿# define _CRT_SECURE_NO_WARNINGS 1
# include <stdio.h>
//关机程序
//1.程序运行起来的时候，就开始倒计时60s关机
//2.如果输入我是🐖，就取消关机
//# include <stdlib.h>
//# include <string.h>
//int main()
//{
//	char input[20] = { 0 };
//	system("shutdown -s -t 3600");
//
//again:
//	printf("将在3600s后关机，若输入我是猪，则取消关机\n");
//	scanf("%s",input);
//	if (strcmp("我是猪", input) == 0)
//	{
//		system("shutdown -a");  
//	}
//	else
//	{
//		goto again;
//	}
//	return 0;
//}
//电脑自动生成1~100的数字
# include <stdlib.h>
# include <time.h>
void menu()
{
	printf("***************************\n");
	printf("*********  1.play *********\n");
	printf("*********  0.exit *********\n");
	printf("***************************\n");
}
void game()
{
	//1.生成1~100之间的随机数
	int r = rand() % 100 + 1;
	//2.猜数字
	int guess = 0;
	int count = 5;
	while (count)//计数值应随之而变化，1恒成立
	{
		printf("\n你还有%d次机会\n", count);
		printf("请猜数字>:");
		scanf("%d", &guess);
		if (guess > r)
		{
			printf("猜大了\n");
		}
		else if (guess < r)
		{
			printf("猜小了\n");
		}
		else 
		{
			printf("恭喜你，猜对了\n");
			break;
		}
		count--;
	}
	if (count == 0)
	{
		printf("你失败了,正确的是:%d\n",r);
	}
}
int main()
{
	 srand((unsigned int)time(NULL));
	//菜单
	menu();
	int input = 0;
	do
	{
		printf("请选择:>");//
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			game();
			break;
		case 0:
			printf("游戏结束\n");
			break;
		default:
			printf("选择错误，重新选择\n");
			break;
		}
		
	} while (input);
	return 0;
}